﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace BYManageInfoSystem
{
    class Fin_PayTaxHkd2Hkd : Fin_PayTaxBase
    {

        public Fin_PayTaxHkd2Hkd(Hashtable SQLStringList, ArrayList arrayList)
            : base(SQLStringList, arrayList)
        {

        }
        protected override Decimal GetRecvAuxiliary2RecvFactor(string strRecvBianNo)
        {
            return 1;
        }
        protected override bool isAllBackTax(Decimal dtTotal, Decimal dtPayedValue, DGBY.Model.FinCheckInvoiceRecordDetailTab_New modelFinCheckInvoiceRecordDetailTab_New)
        {
            if (Math.Abs((dtPayedValue + dtTotal) - (modelFinCheckInvoiceRecordDetailTab_New.HKPercent17
      + modelFinCheckInvoiceRecordDetailTab_New.HKPercent16
      + modelFinCheckInvoiceRecordDetailTab_New.HKPercent15
      + modelFinCheckInvoiceRecordDetailTab_New.HKPercent13
      + modelFinCheckInvoiceRecordDetailTab_New.HKPercent9
      + modelFinCheckInvoiceRecordDetailTab_New.HKPercent5)) < 0.1M)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        protected override void ComputeCometoFacFormulaForFomularSelectOne(Dictionary<Decimal, Decimal> dicPayTaxPercent2InvoiceYuE
           , ref DGBY.Model.FinDepRecvAndPayDetailTab_New modelFinDepRecvAndPayDetailTab_New, Decimal dtThisRecv, Decimal dtThis, string strGongshi)
        {
            string strHuiLvFormular = GetHuiLvFormular(modelFinDepRecvAndPayDetailTab_New);
            string[] strHuiLvFormularSplit = strHuiLvFormular.Split('/');
            Decimal dtHkHuilv = Convert.ToDecimal(strHuiLvFormularSplit[0]);
            //Decimal dtUsdHuilv = Convert.ToDecimal(strHuiLvFormularSplit[1]);

            Decimal dtToFacMoneyTemp = 0;
            string strPayTaxBenJinGongShiTemp = "";

            string strFisrtValue = GetFisrtFormularValue(strGongshi, dtThisRecv);

            foreach (Decimal dtBackTaxPoint in dicPayTaxPercent2InvoiceYuE.Keys)
            {
                Decimal dtPayBenJin = dicPayTaxPercent2InvoiceYuE[dtBackTaxPoint];
                if (dtBackTaxPoint == modelFinDepRecvAndPayDetailTab_New.FactorB)
                {
                    dtToFacMoneyTemp = dtPayBenJin
* dtHkHuilv * modelFinDepRecvAndPayDetailTab_New.FactorA - dtPayBenJin
* dtHkHuilv;




                    if (Math.Abs(dtThis - dtPayBenJin) < 0.5M)
                    {
                        strPayTaxBenJinGongShiTemp =
                  strFisrtValue + " * "
                  + dtHkHuilv.ToString() + " * " + modelFinDepRecvAndPayDetailTab_New.FactorA.ToString()
                  + " - " + dtPayBenJin.ToString("0.00") + " * "
                  + dtHkHuilv.ToString() + " * 1";
                    }
                    else
                    {
                        strPayTaxBenJinGongShiTemp =
                  " ( " + dtThisRecv.ToString("0.00")
+ strGongshi + " - " + (dtThis - dtPayBenJin).ToString("0.00") + " ) " + " * "
                  + dtHkHuilv.ToString() + " * " + modelFinDepRecvAndPayDetailTab_New.FactorA.ToString()
                  + " - " + dtPayBenJin.ToString("0.00") + " * "
                  + dtHkHuilv.ToString() + " * 1";
                    }

                }
                else
                {
                    dtToFacMoneyTemp = dtPayBenJin
* dtHkHuilv * (modelFinDepRecvAndPayDetailTab_New.FactorA + dtBackTaxPoint
- (modelFinDepRecvAndPayDetailTab_New.FactorB)) - dtPayBenJin
* dtHkHuilv;


                    if (Math.Abs(dtThis - dtPayBenJin) < 0.5M)
                    {
                        strPayTaxBenJinGongShiTemp =
                        strFisrtValue + " * "
                        + dtHkHuilv.ToString() + " * " + (modelFinDepRecvAndPayDetailTab_New.FactorA
                        + dtBackTaxPoint - (modelFinDepRecvAndPayDetailTab_New.FactorB)).ToString()
                        + " - " + dtPayBenJin.ToString("0.00") + " * "
                + dtHkHuilv.ToString() + " * 1";
                    }
                    else
                    {
                        strPayTaxBenJinGongShiTemp =
                         " ( " + dtThisRecv.ToString("0.00")
+ strGongshi + " - " + (dtThis - dtPayBenJin).ToString("0.00") + " ) " + " * "
                         + dtHkHuilv.ToString() + " * " + (modelFinDepRecvAndPayDetailTab_New.FactorA
                         + dtBackTaxPoint - (modelFinDepRecvAndPayDetailTab_New.FactorB)).ToString()
                         + " - " + dtPayBenJin.ToString("0.00") + " * "
                 + dtHkHuilv.ToString() + " * 1";
                    }

                }

                modelFinDepRecvAndPayDetailTab_New.ToFacMoney += dtToFacMoneyTemp;

                if (modelFinDepRecvAndPayDetailTab_New.PayTaxBenJinGongShi == null)
                {
                    modelFinDepRecvAndPayDetailTab_New.PayTaxBenJinGongShi
                        = strPayTaxBenJinGongShiTemp;
                }
                else
                {
                    modelFinDepRecvAndPayDetailTab_New.PayTaxBenJinGongShi
                        += " + " + strPayTaxBenJinGongShiTemp;
                }
            }
        }
        protected override void ComputeCometoFacFormulaForFomularSelectZero(Dictionary<Decimal, Decimal> dicPayTaxPercent2InvoiceYuE
    , ref DGBY.Model.FinDepRecvAndPayDetailTab_New modelFinDepRecvAndPayDetailTab_New, Decimal dtThisRecv, Decimal dtThis, string strGongshi)
        {
            string strHuiLvFormular = GetHuiLvFormular(modelFinDepRecvAndPayDetailTab_New);
            string[] strHuiLvFormularSplit = strHuiLvFormular.Split('/');
            Decimal dtHkHuilv = Convert.ToDecimal(strHuiLvFormularSplit[0]);
            Decimal dtUsdHuilv = Convert.ToDecimal(strHuiLvFormularSplit[1]);

            Decimal dtToFacMoneyTemp = 0;
            string strPayTaxBenJinGongShiTemp = "";
            var result2 = from pair in dicPayTaxPercent2InvoiceYuE orderby pair.Value select pair;
            //foreach (Decimal dtBackTaxPoint in dicPayTaxPercent2InvoiceYuE.Keys)

            string strFisrtValue = GetFisrtFormularValue(strGongshi, dtThisRecv);

            foreach (KeyValuePair<Decimal, Decimal> pair in result2)
            {
                Decimal dtBackTaxPoint = pair.Key;
                Decimal dtPayBenJin = dicPayTaxPercent2InvoiceYuE[dtBackTaxPoint];

                if (1.17M - dtBackTaxPoint > 0)
                {
                    dtToFacMoneyTemp =
                    dtPayBenJin
                    * dtHkHuilv / dtUsdHuilv
                    * (dtUsdHuilv - modelFinDepRecvAndPayDetailTab_New.FactorA)
                    * (decimal)1.17 / (1.17M - dtBackTaxPoint)
                    - dtPayBenJin * dtHkHuilv;

                    if (Math.Abs(dtThis - dtPayBenJin) < 0.5M)
                    {
                        strPayTaxBenJinGongShiTemp
    = strFisrtValue + " * " + dtHkHuilv.ToString() + " / " + dtUsdHuilv.ToString() + " * ( "
    + dtUsdHuilv.ToString() + " - " + modelFinDepRecvAndPayDetailTab_New.FactorA.ToString("0.000")
    + " ) * 1.17 /" + (1.17M - dtBackTaxPoint).ToString("0.00") + " - " +
    dtPayBenJin.ToString("0.00") + " * " + dtHkHuilv.ToString();
                    }
                    else
                    {
                        strPayTaxBenJinGongShiTemp
    = " ( " + dtThisRecv.ToString("0.00")
    + strGongshi + " - " + (dtThis - dtPayBenJin).ToString("0.00") + " ) " + " * " + dtHkHuilv.ToString() + " / " + dtUsdHuilv.ToString() + " * ( "
    + dtUsdHuilv.ToString() + " - " + modelFinDepRecvAndPayDetailTab_New.FactorA.ToString("0.000")
    + " ) * 1.17 /" + (1.17M - dtBackTaxPoint).ToString("0.00") + " - " +
    dtPayBenJin.ToString("0.00") + " * " + dtHkHuilv.ToString();
                    }

                }
                else
                {
                    dtToFacMoneyTemp = 0;
                    strPayTaxBenJinGongShiTemp = " 0 ";
                }

                modelFinDepRecvAndPayDetailTab_New.ToFacMoney += dtToFacMoneyTemp;

                if (modelFinDepRecvAndPayDetailTab_New.PayTaxBenJinGongShi == null)
                {
                    modelFinDepRecvAndPayDetailTab_New.PayTaxBenJinGongShi
                        = strPayTaxBenJinGongShiTemp;
                }
                else
                {
                    modelFinDepRecvAndPayDetailTab_New.PayTaxBenJinGongShi
                        += " + " + strPayTaxBenJinGongShiTemp;
                }

            }
        }

        
        
    }
}
